package com.qyer.search.filter;

import static com.qyer.log.WarningLogger.logWarning;
import static com.qyer.search.model.lastminute.SKU.naSKU;

import com.qyer.search.model.SearchParameterOrigin;
import com.qyer.search.model.lastminute.SKU;

import java.util.Map;

/**
 * Created by tangzheng on 16/3/7.
 */
public class StartTimeFilter extends AbstractFilter {

  public StartTimeFilter(Object ... conditions) {
    super(conditions);
  }

  @Override public boolean isValid(Map<String, Object> dataMap, SearchParameterOrigin searchParameterOrigin) {

    long startTime = (long)conditions[0];
    long endTime = (long)conditions[1];

    int id = Integer.valueOf(String.valueOf(dataMap.get(SKU.FIELD_ID)));
    long time1 = Long.valueOf(String.valueOf(dataMap.get(SKU.FIELD_START_TIME)));
    long time2 = Long.valueOf(String.valueOf(dataMap.get(SKU.FIELD_END_TIME)));
    if(time2 == 0)
      time2 = Long.MAX_VALUE;
    if(endTime <= time1 || startTime > time2) {
      //logWarning(naSKU(id), searchParameterOrigin, null);
      return false;
    }
    return true;
  }
}
